CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


obj

  xb    :       "xbee"

  ser   :       "FullDuplexSerial"

var

  long stk[50]

dat
        new_img         file    "xbee_loader_test2.binary"
  
pub go

  cognew(loader, @stk)
  
  'xb.start(26, 27, 9600)
  xb.start(24, 25, 9600)
  
  

  dira[0]~~
  
  repeat
    !outa[0]
    waitcnt(cnt+clkfreq>>1)


pub loader | i

  ser.start(15, 14, 0, 9600)

  dira[10]~
  dira[1]~~
  repeat
    repeat while ina[10]          'repeat until button is pressed
     
    outa[1]~~ 
    ser.str(string("Open, sesame!###"))                   'send string to put loader object into command mode
     
    ser.tx("#")
    ser.tx($a5)
    ser.tx($5a)
     
    ser.tx(44)
    ser.tx(0)
     
     
    repeat i from 0 to 51         'transmit program image
      ser.tx(byte[@new_img + i])
      
     
    ser.tx("#")
    ser.tx("!")
    outa[1]~
    